<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>快速登记成绩</title>

<%@ include file="/common/commonLib.jsp"%>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/courseTaskReview.css'/>" />

<script src="<c:url value='/js/courseTaskSubmit.js'/>" type="text/javascript" charset="utf-8"></script>
<style type="text/css">  
.btns{font-weight: bold;display: inline-block;width: 4rem;height: 3rem;border: #5fb878;background: #5fb878;font-size: 2rem;text-align: center;padding: 5px 0;color: white;border-radius: 4px;box-shadow: 2px 2px 2px #87d889;}
#update-score a:hover{color:#FFFFFF;}
</style>
</head>
<body>
	<div class="container-fluid main">
		<!-- 任务提交情况 -->
		<div class="row">
			<div class="col-md-12">
				<%@include file="/common/header.jsp"%>
			</div>
			<div class="col-md-12">
				<%@include file="common/courseHeader.jsp"%>
			</div>
			<div class="col-md-12">
				<div class="row">
					<div class="col-md-3">
						<%@include file="common/courseLeft.jsp"%>
					</div>
					<div class="col-md-9">
						<div class="row">
							<div class="col-md-12">
								<%@include file="common/courseNavbar.jsp"%>
							</div>
							<div class="col-md-12">
								<div class="tab-nav">
									<a id="task-submit-href1" class="front-nav">任务首页
									</a>&nbsp;>&nbsp;<a id="task-submit-href2" class="front-nav">任务详情
									</a>&nbsp;>&nbsp;<a id="task-submit-href3" class="front-nav">任务分配情况
									</a>&nbsp;>&nbsp;<a id="task-submit-href4"  class="front-nav">任务提交记录
									</a>&nbsp;>&nbsp;<span  class="back-nav">快速登记成绩</span>
								</div>
							</div>
							<div class="col-md-12" style="margin-top:1rem;margin-left:4rem;">
								<div class="row">
									<div class="col-md-12">
										任务名：<a id="task-name" style="color:red;"></a>
									</div>
									<div class="col-md-12">
										所发布的课堂信息：<a id="lesson-date" style="color:blue;"></a>
										上课地点：<a id="lesson-location" style="color:green;"></a>
									</div>
									<div class="col-md-12">
										<a style="color:red;">（提交按钮在右侧）</a>
									</div>
								</div>								
							</div>
							<div class="col-md-12" style="margin-top:2rem;">									
								<div class="row">
									<div class="col-md-1"></div>
									<div class="col-md-10">
										<table class="table table-hover">
											<thead>
												<tr>
													<th width="16%">学号</th>
													<th width="16%">姓名</th>
													<th width="14%">当前状态</th>
													<th width="24%">评分时间</th>
													<th width="15%">分数</th>													
													<th width="15%">操作</th>
												</tr>
											</thead>
											<tbody id="submitList">
												
											</tbody>
										</table>
									</div>
									<div class="col-md-1"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
	</div>
	<!-- 右侧悬浮按钮 -->
<%--	<div style="overflow: hidden;position: fixed;right: 70rem;bottom: 7rem;z-index: 10;">--%>
<%--	    <div style="overflow: hidden;">--%>
<%--	    	<div style="padding-right:1rem;">--%>

<%--			</div>--%>
<%--	    	--%>
<%--	    </div>--%>
<%--    </div>--%>
	<div style="width: 100%;position: absolute">
		<button id="update-score" class="btns" style="width: 100px;height: 40px;line-height: 30px;text-align: center;position: absolute;left: 60%;top: -50px">提交</button>
	</div>

	<div style="height: 50px;">

	</div>
	<%@include file="/common/footer.jsp"%>
</body>
<script>
var data=${data};

$(document).ready(function() {
	if (data.status != "success") {
		layer.alert(data.message);
		return;
	}
	$("#task").css("color","#00b43c");
	changeUrl(data.data.courseId);
	fetchCourse(data.data.courseId);
	$("#task-name").html(data.data.task.title);
	$("#lesson-date").html(data.data.lesson.beginDate+" to "+data.data.lesson.endDate);
	$("#lesson-location").html(data.data.lesson.location);
	$("#update-score").click(updateScore);
	initList(data.data);
	$("#task-submit-href1").attr("href",CONTEXT_PATH + "task/list?courseId=" + data.data.courseId);
 	$("#task-submit-href2").attr("href",CONTEXT_PATH + "task/detail?id=" + data.data.taskId );
 	$("#task-submit-href3").attr("href",CONTEXT_PATH + "taskAssignView/taskMainList?taskId=" + data.data.taskId);
 	$("#task-submit-href4").attr("href",CONTEXT_PATH + "taskSubmitResult/mtlistData?assignId=" + data.data.assignId);
 	
});

var updateScore = function() {
	var tsrlist=data.data.list;
	var list = new Array();
	var id;
	var score;
	var review;
	for(var i=0;i<tsrlist.length;i++){
		id = $("#tsr-id-"+i).val();
		score = $("#new-score-"+i).val();
		if(id >= 0 && score >=0 && score <=100 && score != null && score != ""){
			review={
				id:id,
				score:score
			}
			list.push(review);
		}
	}
	if(list.length > 0){
		var json = {
				batchReview:list,
				courseId:data.data.courseId
		}
			
		$.post(CONTEXT_PATH+"taskSubmitResult/batchReview", {
			data : JSON.stringify(json)
		}, function(data) {
			if(data.status=="success"){
				layer.msg("保存成功！");
				window.location.reload();
			}else{
				layer.msg(data.message+"（评分项请填写0-100的数字）");
			}
		});
	}else {
		layer.msg("您没有任何改动！或者您的所有输入不合法！");
	}
		
}

var initList = function(data){
	var submitList=$("#submitList");
	submitList.empty();
	var list=data.list;
	if(list.length<=0){
		var s="<tr><td colspan=\"6\"><li>无记录</li></td></tr>";
		submitList.append(s);
	}else {
		for(var i=0;i<list.length;i++){
			var item=list[i];
			var s="";
			s+="<tr>";			
			if(item.status=="UNCOMMITTED"){				
				s+="<td title=\""+item.ucode+"\">"+item.ucode+"</td>"
				s+="<td title=\""+item.assignedName+"\">"+item.assignedName+"</td>";
				s+="<td title=\"未提交\">未提交</td>";
				s+="<td>---</td>";
				s+="<td>---</td>";				
			}else if(item.status=="COMMITTED"){				
				s+="<td title=\""+item.ucode+"\">"+item.ucode+"</td>"
				s+="<td title=\""+item.assignedName+"\">"+item.assignedName+"</td>";
				s+="<td title=\"已提交\">已提交</td>";
				s+="<td>---</td>";
				s+="<td>---</td>";
			}else{				
				s+="<td title=\""+item.ucode+"\">"+item.ucode+"</td>"
				s+="<td title=\""+item.assignedName+"\">"+item.assignedName+"</td>";
				s+="<td title=\"已评分\">已评分</td>";				
				s+="<td title=\"上次评分时间"+item.markDate+"\">"+item.markDate+"</td>";
				s+="<td id=\"now-score\" title=\"当前成绩："+item.score+"\">"+item.score+"</td>";
			}
			
			s+="<td title=\"操作\">";
				s+="<div class=\"control-group\">";														
				s+="<input id=\"tsr-id-"+i+"\" name=\"score\" type=\"hidden\" value=\""+item.id+"\"/>";
				s+="<input id=\"new-score-"+i+"\" name=\"score\" type=\"text\" value=\"\"/>";		
																
				s+="</div>";
			s+="</td>";
			s+="</tr>"
			submitList.append(s);
		}
	}
}
</script>
</html>